<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of imtransform2</title>
  <meta name="keywords" content="imtransform2">
  <meta name="description" content="Applies a linear or nonlinear transformation to an image I.">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../m2html.css">
</head>
<body>
<a name="_top"></a>
<!-- menu.html images -->
<h1>imtransform2
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>Applies a linear or nonlinear transformation to an image I.</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>function J = imtransform2( I, H, varargin ) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre class="comment"> Applies a linear or nonlinear transformation to an image I.

 Takes the center of the image as the origin, not the top left corner.
 Also, the coordinate system is row/column format, so H must be also.

 The bounding box of the image is set by the BBOX argument, a string that
 can be 'loose' (default) or 'crop'. When BBOX is 'loose', J includes the
 whole transformed image, which generally is larger than I. When BBOX is
 'crop' J is cropped to include only the central portion of the
 transformed image and is the same size as I. The 'loose' flag is
 currently inexact (because of some padding/cropping). Preserves I's type.

 USAGE
  J = imtransform2( I, H, varargin )

 INPUTS - common
  I          - input image [converted to double]
  H          - 3x3 nonsingular homography matrix
  varargin   - additional params (struct or name/value pairs)
    .method    - ['linear'] 'nearest', 'spline', 'cubic' (for interp2)
    .bbox      - ['crop'] or 'loose'
    .show      - [0] figure to use for optional display
    .pad       - [0] padding value (scalar, 'replicate' or 'none')
    .useCache  - [0] optionally cache precomp. for given transform/dims.
    .us        - [] can specify source r/c for each target (instead of H)
    .vs        - [] can specify source r/c for each target (instead of H)

 OUTPUTS
  J       - transformed image

 EXAMPLE - rigid transformation (rotation + translation)
  I=imread('peppers.png');
  R = rotationMatrix(pi/4); T=[1; 3]; H=[R T; 0 0 1];
  J = imtransform2(I,H,'show',1,'pad','replicate');

 EXAMPLE - general homography (out of plane rotation)
  load trees; I=X;
  S=eye(3); S([1 5])=1/500; % zoom out 500 pixels
  H=S^-1*rotationMatrix([0 1 0],pi/4)*S;
  J = imtransform2(I,H,'bbox','loose','show',1);

 EXAMPLE - rotation using three approaches (and timing)
  load trees; I=imResample(X,4); angle=35; method='bilinear';
  % (1) rotate using imrotate (slow)
  tic; J1 = imrotate(I,angle,method,'crop'); toc
  % (2) rotate using a homography matrix
  R=rotationMatrix(angle/180*pi); H=[R [0; 0]; 0 0 1];
  tic; J2 = imtransform2(I,H,'bbox','crop','method',method); toc
  % (3) rotate by explicitly specifying target rs/cs
  m=size(I,1)+4; n=size(I,2)+4; m2=(m-1)/2; n2=(n-1)/2;
  [cs,rs]=meshgrid(-n2:n2,-m2:m2); vs=R*[cs(:) rs(:)]';
  us=reshape(vs(2,:),m,n)-rs; vs=reshape(vs(1,:),m,n)-cs;
  tic, J3=imtransform2(I,[],'us',us,'vs',vs,'method',method); toc
  % compare all results
  figure(1); clf; subplot(3,2,1); im(I); subplot(3,2,2); im(J1);
  subplot(3,2,3); im(J2); subplot(3,2,4); im(abs(J1-J2)); title('J1-J2')
  subplot(3,2,5); im(J3); subplot(3,2,6); im(abs(J2-J3)); title('J2-J3')

 See also <a href="textureMap.html" class="code" title="function [J,boundX,boundY] = textureMap( I, rsDst, csDst, bbox, fillVal )">TEXTUREMAP</a>, INTERP2

 Piotr's Computer Vision Matlab Toolbox      Version 3.01
 Copyright 2014 Piotr Dollar.  [pdollar-at-gmail.com]
 Licensed under the Simplified BSD License [see external/bsd.txt]</pre></div>





<!-- Start of Google Analytics Code -->
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-4884268-1");
pageTracker._initData();
pageTracker._trackPageview();
</script>
<!-- end of Google Analytics Code -->

<hr><address>Generated by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" target="_parent">m2html</a></strong> &copy; 2003</address>
</body>
</html>
